<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>显示一个电子时钟</title>
</head>
<body onload="starttime()">
<div id="txt"></div>
<script type="text/javascript">
    function starttime() {
        var today=new Data();
        var h=today.getHours();
        var m=today.getMinutes();
        var s=today.getSeconds();

        m=checktime(m);
        s=checktime(s);
        document.getElementById('txt').innerHTML=h+":"+m+":"+s;
        today=setTimeout('starttime()',500);
    }
    function checktime(i) {
        if (i<10){i="0"+i}
        return i
    }
</script>
</body>
</html>